//
//  WBVisitorView.swift
//  0829-Weibo
//
//  Created by 毕仲阳 on 16/8/30.
//  Copyright © 2016年 mycompany. All rights reserved.
//

import UIKit

class WBVisitorView: UIView {

    override init(frame: CGRect) {
        super.init(frame: frame)
        setUI()
        startAnimation()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func setUI()
    {
        backgroundColor = UIColor(white: 237/255, alpha: 1)
        //添加控件
        addSubview(circleView)
        addSubview(maskIconView)
        addSubview(iconView)
        addSubview(messageLabel)
        addSubview(registerButton)
        addSubview(loginButton)
        //添加约束
        iconView.snp_makeConstraints { (make)->Void in
            make.center.equalTo(self)
        }
        circleView.snp_makeConstraints { (make)->Void in
            make.center.equalTo(self)
        }
        messageLabel.snp_makeConstraints { (make)->Void in
            make.centerX.equalTo(iconView)
            make.top.equalTo(circleView.snp_bottom).offset(16)
            make.width.equalTo(224)
        }
        registerButton.snp_makeConstraints { (make)->Void in
            make.leading.equalTo(messageLabel)
            make.width.equalTo(100)
            make.height.equalTo(35)
            make.top.equalTo(messageLabel.snp_bottom).offset(16)
        }
        loginButton.snp_makeConstraints { (make)->Void in
            make.trailing.equalTo(messageLabel)
            make.width.height.equalTo(registerButton)
            make.top.equalTo(registerButton)
        }
        maskIconView.snp_makeConstraints { (make)->Void in
            make.top.left.right.equalTo(self)
            make.bottom.equalTo(messageLabel)
        }
        
        
    }
    
    func setVisitorViewInfo(imgName:String?,message:String?)
    {
        if imgName != nil{
            circleView.isHidden = true
            iconView.image = UIImage(named: imgName!)
            messageLabel.text = message
        }
        else
        {
            messageLabel.text = message
            startAnimation()
        }
    }
    func startAnimation()
    {
        let ani = CABasicAnimation(keyPath: "transform.rotation")
        ani.toValue = M_PI*2
        ani.duration = 20
        ani.repeatCount = MAXFLOAT
        
        ani.isRemovedOnCompletion = false
        circleView.layer.add(ani, forKey: nil)
    }
    //房子的图标
   private lazy var iconView = UIImageView(image: #imageLiteral(resourceName: "visitordiscover_feed_image_house"))
    //转圈
   private lazy var circleView = UIImageView(image: #imageLiteral(resourceName: "visitordiscover_feed_image_smallicon"))
    //文字label
   private lazy var messageLabel :UILabel = {
       let label = UILabel(textColor: UIColor.darkGray, fontSize: 14)
        label.text = "哈哈哈哈啊哈哈哈哈哈哈哈哈哈哈哈哈"
        label.numberOfLines = 0
        label.textAlignment = .center
        return label
    }()
    //遮罩
    private lazy var maskIconView = UIImageView(image: #imageLiteral(resourceName: "visitordiscover_feed_mask_smallicon"))
    //注册按钮
     lazy var registerButton : UIButton = {
        let button = UIButton(textColor: UIColor.orange, fontSize: 14)
        button.setTitle("注册", for: UIControlState.normal)
        button.setBackgroundImage(#imageLiteral(resourceName: "common_button_white"), for: UIControlState.normal)
        return button
    }()
    
    //登录按钮
     lazy var loginButton : UIButton = {
        let button = UIButton(textColor: UIColor.darkGray, fontSize: 14)
        button.setTitle("登录", for: UIControlState.normal)
        button.setBackgroundImage(#imageLiteral(resourceName: "common_button_white"), for: UIControlState.normal)
        return button
    }()
    
}
